#include <iostream>
#include <queue>
using namespace std;
//#include "reopen"

class milk{
public:
	int first,second;
};
bool operator<(milk a,milk b){
	return a.first>b.first;
}

int main(void){
//	reopen("P1208_t");
	long long int n,sum=0;
	int m;
	cin>>n>>m;

	milk temp;
	priority_queue<milk> a;
	for(int i=0;i<m;i++){
		cin>>temp.first>>temp.second;
		a.push(temp);
	}
	while(n>0){
		temp.first=a.top().first;
		temp.second=a.top().second;
//		cout<<temp.first<<" "<<n<<" ";
		if(temp.second<=n){
			n-=temp.second;
			sum+=temp.first*temp.second;
		}else{
			sum+=n*temp.first;
			n=0;
		}
//		cout<<sum<<endl;
		a.pop();
	}
	cout<<sum;
	return 0;
}